<template>
  <div class="signin-container">
    <el-card class="box-card" shadow="hover">
      <h2>Sign Your Acount</h2>
      <el-form
        :model="signinForm"
        status-icon
        :rules="rules"
        ref="signinForm"
        class="signin-ruleForm"
      >
        <el-form-item label="" prop="username">
          <el-input
            placeholder="请输入用户账号"
            v-model="signinForm.username"
          ></el-input>
        </el-form-item>
        <el-form-item label="" prop="password">
          <el-input
            placeholder="请输入用户密码"
            type="password"
            v-model="signinForm.password"
          ></el-input>
        </el-form-item>
        <el-form-item label="" prop="email">
          <el-input
            placeholder="请输入电子邮箱"
            type="email"
            v-model="signinForm.email"
          ></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary">提交注册</el-button>
      <el-button type="success" @click="change">返回登陆</el-button>
    </el-card>
  </div>

</template>

<script>
export default {
  props: {
    formType: String
  },
  data() {
    const validateEmail = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请正确填写邮箱'));
        } else {
          if (value !== '') { 
            var reg=/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
            if(!reg.test(value)){
              callback(new Error('请输入有效的邮箱'));
            }
          }
          callback();
        }
      };
    return {
      signinForm: {
        username: '',
        password: '',
        email: ''
      },
        rules: {
        username: [
          { required: true, message: "请输入用户账号", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入用户密码", trigger: "blur" },
        ],
        email: [
          { validator: validateEmail, trigger: "blur" },
        ],
      },
    }
  },
  methods: {
    change() {
      this.$emit('update:formType', 'LoginForm')
    },
  }
}
</script>

<style lang="less" scoped>
.signin-container {
  width: 80%;
  height: auto;
  margin: 0 auto;

  .box-card {
    .signin-ruleForm {
      width: 90%;
      margin: 0 auto;
    }
  }
}
</style>